﻿using System;
using System.Collections.Generic;
using System.Text;
using MongoDB.Bson;
using MongoDB.Driver;
using FreeSql.DataAnnotations;

namespace DAL
{
    //静态类，可直接调用
    class SqlHelper
    {
        //MongoDB连接字符串
        public static string Mongocnetstr = "mongodb://127.0.0.1:27017";
        //MySql连接字符串
        public static string MySqlcnetstr = "Data Source=127.0.0.1;Port=3306;User ID=root;Password=root;Initial Catalog=testshop;Charset=utf8;SslMode=none;Min pool size=1;Command Timeout = 300";

        //MongoDB数据库名
        public static string dbName = "what";
        //获取MongoDB
        public static IMongoDatabase GetMongoClient()
        {
            MongoClient client = new MongoDB.Driver.MongoClient(Mongocnetstr);//创建连接
            IMongoDatabase database = client.GetDatabase(dbName);
            return database;
        }
        //获取FreeSql
        public static IFreeSql GetFreeSql()
        {
            IFreeSql Fsql = new FreeSql.FreeSqlBuilder()
            .UseConnectionString(FreeSql.DataType.MySql, MySqlcnetstr)
            .UseAutoSyncStructure(true)
            .Build();
            return Fsql;
         }
    }
}
